<script setup>
let message = '32r';
message = 'sdffd';
message = 23;

/** @type { string | number } */
let foo = 'foo';
foo = 123;

/** @type { { id: number, name: string } } */
const person = {
  id: 1,
  name: '张三',
};

/** @type {import('@/types/index').add} */
function add(a, b) {
  return a + b;
}

add(100, 200);

/** @type {import('@/types/index').myRef} */
function myRef(val) {
  return { value: val };
}

const count = myRef(0);
console.log(count.value);

/** @type { { value: (string | number)[] } } */
const list = myRef([]);
console.log(list.value);
list.value.push('测试');
list.value.push(100);
list.value.push(true);

/** @type { { value: string[] } } */
const arr = myRef([]);
console.log(arr.value);

const options = {
  /** @type { function(number, number): number } */
  add: function (a, b) {
    return a + b;
  },
  /** @type { (a: number, b: number) => number } */
  sub: (a, b) => a - b,
  /**
   * 除法
   * @type { (a: number, b: number) => number }
   * @param a 被除数
   * @param b 除数
   */
  divide(a, b) {
    return a / b;
  },
  showTip: false,
  /**
   * @type { 'off' | 'wraning' | 'error' }
   */
  type: 'off',
};

/** @type import('@/types/index').options */
const options2 = {
  showTip: true,
  type: 'wraning',
  add: function (a, b) {
    return a + b;
  },
  sub: (a, b) => a - b,
  divide(a, b) {
    return a / b;
  },
};
</script>
